<div class="modal fade " id="maintainCustomerModal"  role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">客户信息维护</h3>
            </div>
            <form class="form-horizontal" role="form" id="maintainCustomerForm"  method="post"  enctype="multipart/form-data">
                <div class="box-body">
                    <div class="form-group">
                        <input id="customerId" name="customerId" type="text" disabled="disabled" class="form-control" style="display:none;">

                        <label class="col-sm-2 control-label" for="customerNameLabel">客户名称</label>
                        <div class="col-sm-10">
                            <input id="customerName" name="customerName" type="text" class="form-control">
                        </div>
                    </div>
                </div>
                <div class="box-footer">
                    <button type="button" class="btn btn-danger pull-left" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary pull-right" onclick="saveCustomer()">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
<#include "../public/js.ftl" >
<#include "../public/css.ftl">
<script src="/js/common.js"></script>
<script>
    function maintainCustomerInit() {
        //初始化产品维护画面
        $("#customerId").val("");
        $("#customerName").val("");
    }

    function modifyCustomerInit(data) {
        //查询数据设置到修改画面对应栏位
        $("#customerId").val(data.customerId);
        $("#customerName").val(data.customerName);
    }

    function saveCustomer(){
        //客户ID
        var customerId = $("#customerId").val();

        //客户名称
        var customerName = $("#customerName").val();

        //去除空格
        customerName = strTrim(customerName);

        if (customerName == "") {
            toastr['error']("客户名称不能为空", '异常');
            return;
        }

        //检查客户名称长度不能超过100个字符
        var length = strlen(customerName);
        if (length > 100) {
            toastr['error']("客户名称长度不能超过100个字符", '异常');
            return;
        }

        var data = {
            customerId : customerId,
            customerName : customerName
        };

        var url = "/customermanager/maintaincustomer";

        postReq(url, data, function (result) {
            if (result.success) {
                maintainCustomerInit();
                $("#customerTable").bootstrapTable("refresh");
                $("#maintainCustomerModal").modal("hide");
                toastr['success']('产品保存成功', '提示');
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }
</script>
